package com.example.mobile2021606128wje0330;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private RadioGroup radGupCarType;
    private RadioButton radBtnMainSaloon;
    private RadioButton radBtnMainMVP;
    private RadioButton radBtnMainSUV;
    private RadioGroup radGupMainLine;
    private RadioButton radBtnMainLine1;
    private RadioButton radBtnMainLine2;
    private RadioButton radBtnMainLine3;
    private RadioButton radBtnMainLine4;
    private Button btnMainCreate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        //设置第一组单项选中状态改变的监听器
        radGupCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton",radioButton.getText().toString());
            }
        });
        //设置第二组单项选中状态改变的监听器
        radGupMainLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i){
                RadioButton radioButton = findViewById(i);
                    Log.i("RadioButton",radioButton.getText().toString());
         }
        });
        btnMainCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg = "";
                int carId=radGupCarType.getCheckedRadioButtonId();
                if (carId!=-1){
                    msg=((RadioButton)findViewById(carId)).getText().toString();
                }else {
                    msg = "未选车型";
                }
                int LineId=radGupMainLine.getCheckedRadioButtonId();
                if (LineId!=-1){
                    msg+=","+((RadioButton)findViewById(LineId)).getText().toString();
                }else {
                    msg += "未选车间";
                }
                Log.i("点击按钮",msg);
            }
        });

    }

    private void initView() {
        radGupCarType = (RadioGroup) findViewById(R.id.radGup_car_type);
        radBtnMainSaloon = (RadioButton) findViewById(R.id.radBtn_main_saloon);
        radBtnMainMVP = (RadioButton) findViewById(R.id.radBtn_main_MVP);
        radBtnMainSUV = (RadioButton) findViewById(R.id.radBtn_main_SUV);
        radGupMainLine = (RadioGroup) findViewById(R.id.radGup_main_Line);
        radBtnMainLine1 = (RadioButton) findViewById(R.id.radBtn_main_Line1);
        radBtnMainLine2 = (RadioButton) findViewById(R.id.radBtn_main_Line2);
        radBtnMainLine3 = (RadioButton) findViewById(R.id.radBtn_main_Line3);
        radBtnMainLine4 = (RadioButton) findViewById(R.id.radBtn_main_Line4);
        btnMainCreate = (Button) findViewById(R.id.btnMainCreate);
    }
}